#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;


int main(){
//	int n;
//	cin>>n;
	freopen("P1020_4.in","r",stdin);
	vector<int> a;
	vector<int> dp;
	a.push_back(-1);
	dp.push_back(-1);
	dp.push_back(-1);
	int l;
	while(scanf("%d",&l)!=EOF)
		a.push_back(l);
	
//	scanf("%s\n",&l);
//	for(int i=0;i<l.length())
	int R=0;
	for(int i=a.size()-1;i>=1;i--){
		vector<int> b;
		b = dp;
		if(a[i] >= dp[R]){
			dp[++R] = a[i];
			dp.push_back(-1);
//			R++;
		}
		else
			dp[upper_bound(dp.begin(),dp.end()-1,a[i])-dp.begin()] = a[i];
		if(b == dp){
			cout<<i<<endl<<endl<<endl;
			return 0;
		}
//		cout<<a[i]<<":"<<endl;
//		for(int i=0;i<dp.size();i++)
//			cout<<dp[i]<<" ";
//		cout<<endl;
	}
	cout<<R<<endl;
	R=0;
	dp.clear();
	dp.push_back(-1);
	dp.push_back(-1); 
	for(int i=1;i<a.size();i++){
		if(a[i] > dp[R]){
			dp[++R] = a[i];
			dp.push_back(-1);
//			R++;
		}
		else
			dp[lower_bound(dp.begin(),dp.end()-1,a[i])-dp.begin()] = a[i];
	}
	cout<<R;
	return 0;
}
